﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class TransformExtension {

    public static Vector3 GetRelativePositon(this Transform relative,Vector3 source)
    {
        Matrix4x4 relativeToLocalMM = relative.worldToLocalMatrix;
        Vector3 result = relativeToLocalMM.MultiplyPoint3x4(source);

        return result;
    }

    public static Vector3 GetRelativePositon( this Transform relative,Transform source)
    {
        Matrix4x4 relativeToLocalMM = relative.worldToLocalMatrix;
        Matrix4x4 selfMM = source.localToWorldMatrix;

        Vector3 selfPos = source.position;
        Vector3 result = relativeToLocalMM.MultiplyPoint3x4(selfPos);

        return result;
    }

    static public void SetTransfrom(this Transform tf, int x, int y, int z, bool isLocal = true)
    {
        tf.transform.localPosition = new Vector3(tf.transform.localPosition.x + x
                                                  , tf.transform.localPosition.y + y
                                                  , tf.transform.localPosition.z + z);
    }

}
